<?php
	
	include_once "inc/defines.php";
	
	$unquoted = array("id_grptp", "id_parcours");
	$id = $_POST["id"];
	unset($_POST["id"]);
	$sqlQuery = "UPDATE ".ETUDIANT_TABLE." SET ";
	$it = new CachingIterator(new ArrayIterator($_POST));
	foreach($it as $column=>$value) {
		if(!in_array($column, $unquoted))
			$sqlQuery .= $column."=\"".$value."\""; //pour les strings, la valeur doit etre entre guillemets dans la requete
		else
			$sqlQuery .= $column."=".$value;
		if($it->hasNext())
			$sqlQuery .= ", ";
	}
	$sqlQuery .= " WHERE id_etud=".$id.";";
	$db = new PDO(SERVER.":host=".HOST.";dbname=".BASE, USER, PASS);
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$st = $db->prepare($sqlQuery);
	$st->execute();
	header('Location: '.$_SERVER['HTTP_REFERER'], true, 302); //revenir a la page precedante en rafraichissant la page

?>
